package com.bdzl.admin.controller.sys;


import java.util.List;
import java.util.Map;


import com.bdzl.admin.service.sys.NoticeService;
import com.bdzl.pub.controller.BaseController;
import com.bdzl.pub.entity.sys.NoticeDO;
import com.bdzl.pub.util.param.PageUtils;
import com.bdzl.pub.util.param.Query;
import com.bdzl.pub.util.param.R;
import org.springframework.stereotype.Controller;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * 系统公告表
 * 
 * @author yangyicai
 * @email yangyicai@foxmail.com
 * @date 2021-05-24 13:57:36
 */
 
@Controller
@RequestMapping("/bdzl/notice")
public class NoticeController extends BaseController {
	@Autowired
	private NoticeService noticeService;
	
	@GetMapping()
	String Notice(){
	    return "bdzl/notice/notice";
	}
	
	@ResponseBody
	@GetMapping("/list")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<NoticeDO> noticeList = noticeService.list(query);
		int total = noticeService.count(query);
		PageUtils pageUtils = new PageUtils(noticeList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	String add(){
	    return "bdzl/notice/add";
	}

	/**
	 * 详情
	 */
	@ResponseBody
	@PostMapping("/edit")
	NoticeDO edit(@RequestBody NoticeDO notice){
		notice = noticeService.get(notice.getNotId());
	    return notice;
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@Transactional
	public R save(@RequestBody NoticeDO notice){
		if(noticeService.save(notice)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@Transactional
	public R update(@RequestBody NoticeDO notice){
		noticeService.update(notice);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	public R remove(@RequestBody NoticeDO notice){
		if(noticeService.remove(notice.getNotId())>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	public R remove(@RequestParam("ids[]") Integer[] notIds){
		noticeService.batchRemove(notIds);
		return R.ok();
	}
	
}
